﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VINETLIFE.BL;
using VINETLIFE.DO;
using System.Web.UI.HtmlControls;

namespace VINETLIFE
{
    public partial class VideoDetail : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["ID"]))
            {
                if (!IsPostBack)
                {
                    int AlbumID = int.Parse(Request.QueryString["ID"].ToString());
                    rptImagesDataSource(AlbumID);

                    cmsAlbumDO objAlbum = new cmsAlbumBL().Select(new cmsAlbumDO() { AlbumID = AlbumID});
                    Page.Title = objAlbum.Title + " | " + Ultility.WebTitle();

                    sysConfigDO objConfig = new sysConfigDO();
                    objConfig.ConfigID = 2;

                    objConfig = new sysConfigBL().Select(objConfig);


                    HtmlMeta metaKey = new HtmlMeta();
                    metaKey.Name = "keywords";
                    metaKey.Content = objConfig.ConfigValue;
                    Page.Header.Controls.Add(metaKey);


                    HtmlMeta metaDesc = new HtmlMeta();
                    metaDesc.Name = "description";
                    metaDesc.Content = objAlbum.Description;
                    Page.Header.Controls.Add(metaDesc);
                }
            }
            else if (!string.IsNullOrEmpty(Request.QueryString["DetailID"]))
            {
                int MediaID = int.Parse(Request.QueryString["DetailID"].ToString());
                LoadVideo(MediaID);

                MediaDO objMedia = new MediaBL().Select(new MediaDO() { MediaID = MediaID });
                Page.Title = objMedia.Title + " | " + Ultility.WebTitle();

                sysConfigDO objConfig = new sysConfigDO();
                objConfig.ConfigID = 2;

                objConfig = new sysConfigBL().Select(objConfig);


                HtmlMeta metaKey = new HtmlMeta();
                metaKey.Name = "keywords";
                metaKey.Content = objConfig.ConfigValue;
                Page.Header.Controls.Add(metaKey);


                HtmlMeta metaDesc = new HtmlMeta();
                metaDesc.Name = "description";
                metaDesc.Content = objMedia.Description;
                Page.Header.Controls.Add(metaDesc);
            }
            else
            {
                Response.Redirect("/thu-vien-video/");
            }
        }

        private void LoadVideo(int MediaId)
        {
            MediaDO itemDO = new MediaDO();
            itemDO.MediaID = MediaId;
            itemDO = new MediaBL().Select(itemDO);
            string VideoURL = itemDO.MediaUrl.ToString();
            int albumID = itemDO.AlbumID;
            rptImagesDataSource(albumID);
            if (VideoURL != "")
            {
                videoString.Text = Myfunction.GetYouTubeScript(VideoURL, 700, 500);
                video.Visible = true;
            }
        }

        private void rptImagesDataSource(int AlbumID)
        {
            rptImages.DataSource = new MediaBL().GetByAlbum(AlbumID);
            rptImages.DataBind();
        }

        public string Change_AV(string s)
        {
            return Ultility.Change_AV(s);
        }
    }
}